package com.demo.auth.controller;

import com.demo.common.util.R;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import lombok.SneakyThrows;
import org.apache.commons.lang.StringUtils;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author YT
 * @date 2019-07-08
 */
@RestController
public class TestController {

    @GetMapping("/test/{id}")
    public R getId(@PathVariable String id){
        return new R<>(id);
    }

    @GetMapping("/user")
    @SneakyThrows
    public R getUser(Authentication authentication, HttpServletRequest request){

//        String header = request.getHeader("Authorization");
//        String token = StringUtils.substringAfter(header, "bearer ");
//
//        Claims claims = Jwts.parser().setSigningKey("yt".getBytes("utf-8")).parseClaimsJws(token).getBody();
//        String blog = (String) claims.get("blog");

        return new R<>(authentication);
    }
}
